package terra.model;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;

import terra.managers.ResourceManager;

public class Arrow extends GameObject {

	float speed,gravity,yAcceleration,alpha = 1f;
	double imageAngle,angle;
	public boolean stopped = false;
	public long time;

	public Arrow(){
		setType(ObjectType.ARROW);
	}
	
	public void setSGA(float speed2, float gravity2, double angle2) {
		speed = speed2;
		gravity = gravity2;
		angle = angle2;
	}
	
	public void update(int delta){
		if (stopped){
			alpha = (time+2000L-System.currentTimeMillis())/30f*0.01f;
			return;
		}
		float oldY = getY();
		float oldX = getX();
		setX(getX() + (float) ((speed/1000f)*delta*Math.cos(Math.toRadians(angle-90))));
		setY(getY() + (float) ((speed/1000f)*delta*Math.sin(Math.toRadians(angle-90))));
		yAcceleration += gravity/1000f*delta;
		setY(getY()+yAcceleration);
		imageAngle = (-Math.toDegrees(Math.atan2(oldX-getX(),oldY-getY())));
	}
	
	public void render(Graphics g){
		Image img = ResourceManager.getImage("arrow");
		img = img.getScaledCopy(getW(), getH());
		img.setAlpha(alpha);
		g.rotate(getX()+getW()/2, getY()+getH()/2, (float) (imageAngle-90));
		img.drawCentered(getX()+getW()/2, getY()+getH()/2);
		g.rotate(getX()+getW()/2, getY()+getH()/2, (float) -(imageAngle-90));
	}	
	
	
}
